/*
 * SimpleFileFilter.java
 *
 * Created on 16.08.2007, 09:58:41
 *
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.cse.emea.jct.utils;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author jtrapp
 */
public class SimpleFileFilter extends FileFilter {

    private String[] suffixes;
    private String description = "";
    private String suffixLine = "";

    public SimpleFileFilter(String commaSeparatedSuffixes, String description) {
        this.suffixLine = commaSeparatedSuffixes;
        suffixes = commaSeparatedSuffixes.split(",");
        this.description = description;
    }

    @Override
    public boolean accept(File file) {
        if (file.isDirectory()) {
            return true;
        } else {
            for (String suffix : suffixes) {
                if (file.getName().endsWith(suffix)) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public String getDescription() {
        return description + " (" + suffixLine + ")";
    }
}
